<?php
namespace app\home\controller;
use think\Controller;
use app\model\Truck as Truck;
use think\Db;
use think\Loader;
class Index extends Base
{
    public function index()
    {
        return $this->fetch('index');
    }

    public function system(){
        return $this->fetch('system');
    }

    public function camera(){
        return $this->fetch('camera');
    }

    public function report(){
        return $this->fetch('report');
    }

    public function insertByHand(){
        return $this->fetch('insertbyhand');
    }

    public function exportNormalReport(){        
        $timeArea = input('timeArea');
        $billDate = input('billDate');
        $goodsName = input('goodsName');
        $sendUnit = input('sendUnit');
        $receiveUnit = input('receiveUnit');
        $fullOperator = input('fullOperator');
        $houseId = input('houseId');
        $billDateStart = input('billDateStart');
        $billDateEnd = input('billDateEnd');
        $billCode = input('billCode');
        $truckCode = input('truckCode');
        $position = input('position');
        $route = input('route');
        $excavator = input('excavator');
        $list = normalReport($timeArea,$billDateStart,$billDateEnd,$billDate,$goodsName,$sendUnit,$receiveUnit,$fullOperator,$billCode,$truckCode,$position,$route,$excavator,$houseId);
        foreach($list as $k => $v){
            $list[$k]['billDate'] = date('Y-m-d',$v['billDate']);
            $list[$k]['emptyTime'] = date('H:i:s',$v['emptyTime']);
            $list[$k]['fullTime'] = date('H:i:s',$v['fullTime']);
        }
        $houseInfo = session('TX_HOUSE');
        $houseName = $houseInfo['houseName'];
        $user = session('TX_USERS');
        $filds = ['billId','billCode','billDate','goodsName','truckCode','driver','emptyWeigh','fullWeigh','weigh','sendUnit','receiveUnit','excavator','position','route','emptyTime','fullTime','emptyOperator','fullOperator','printCount','houseName','truckType','locked','picUrl','dataFlag'];
        $fildsDesc = array('ID','磅单编号','过磅日期','物资名称','车牌号码','司机姓名','皮重','毛重','净重','发货单位','收货单位','钩机号','发货位置','发运路线','检皮时间','检重时间','检皮人员','检重人员','打印次数','磅房名称','车辆型号','是否审核','图片路径','删除标记');
        makeRport($list,$fildsDesc,$filds,['houseName'=>$houseName,'type'=>'日报表','op'=>$fullOperator]);
    }


    public function accounting(){
        return $this->fetch('accounting');
    }


    public function table(){
        return $this->fetch('table');
    }

    public function test(){
    	//$t = strtotime('2017-10-01');
    	/*$t = time();
    	print_r($t);*/
    	//return $this->fetch('test');
        /*$t = new Truck();
        $where['truckCode'] = 'T01';
        $arr=array('emptyWeigh'=>180000,'weighDate'=>time(),'emptyOperator'=>'管理员');
        $rs = $t->setEmpty($where,$arr);
        print_r($rs);*/
        //scaleIsLegal('T01',1,1);
        /*print_r(strtotime(date('Y-m-d',time())));
        echo '<br/>';
        print_r(md5('123456' . md5('123456')) . '-----' . md5('654321' . md5('654321')));*/
        //return $this->fetch('index');
        /*$t = strtotime(date('Y-m-d h:i',time()));*/
        /*$t = date('Y-m-d H:i:s',1528167660);
        $a = date('Y-m-d H:i:s',1527837607);
        print_r($t);
        echo "<br/>";
        print_r($a);*/
        /*header( "Content-type: image/jpeg");
        $filename = 'd:\test\DLA201806190002.jpg';
        $rs = FileUpload($filename,'d.iyanhong.com:8088/home/apps/uploadimg');
        print_r($rs);*/

        /***
        *
        *导入车辆信息
        *
        ***/
        /*Loader::import('phpexcel.PHPExcel.IOFactory');
        Loader::import('phpexcel.PHPExcel.Reader.Excel5');
        $objReader =\PHPExcel_IOFactory::createReader('Excel2007');
        $file_name = ROOT_PATH . 'public\upload\trucklist.xlsx';
        $obj_PHPExcel =$objReader->load($file_name, $encode = 'utf-8');
        $excel_array=$obj_PHPExcel->getsheet(0)->toArray();
        $arr = array();
        if(!empty($excel_array)){
            foreach($excel_array as $k => $v){
                $tmp = [];
                $tmp['truckCode'] = $v[0];
                $tmp['driver'] = $v[1];
                $tmp['truckOwner'] = $v[1];
                $tmp['truckType'] = $v[2];
                $tmp['emptyWeigh'] = $v[3];
                $tmp['emptyOperator'] = '管理员';
                $tmp['weighDate'] = strtotime(date('Y-m-d',time()));
                $arr[] = $tmp;
            }
            $m = new Truck();
            $rs = $m->insertAll($arr);
            print_r($rs);
        }*/

        /***
        *
        *导入单位信息
        *
        ***/

        /*Loader::import('phpexcel.PHPExcel.IOFactory');
        Loader::import('phpexcel.PHPExcel.Reader.Excel5');
        $objReader =\PHPExcel_IOFactory::createReader('Excel2007');
        $file_name = ROOT_PATH . 'public\upload\CustomerDoc.xlsx';
        $obj_PHPExcel =$objReader->load($file_name, $encode = 'utf-8');
        $excel_array=$obj_PHPExcel->getsheet(0)->toArray();
        $arr = array();
        if(!empty($excel_array)){
            foreach($excel_array as $k => $v){
                $tmp = [];
                $tmp['customerName'] = $v[0];
                $tmp['receiveHouse'] = '1,2,3,4';
                $arr[] = $tmp;
            }
            $rs = Db::name('customer')->insertAll($arr);
            print_r($rs);
        }*/



        /***
        *
        *导入车牌前辍
        *
        ***/

        /*Loader::import('phpexcel.PHPExcel.IOFactory');
        Loader::import('phpexcel.PHPExcel.Reader.Excel5');
        $objReader =\PHPExcel_IOFactory::createReader('Excel2007');
        $file_name = ROOT_PATH . 'public\upload\TruckCodeFirstDoc.xlsx';
        $obj_PHPExcel =$objReader->load($file_name, $encode = 'utf-8');
        $excel_array=$obj_PHPExcel->getsheet(0)->toArray();
        $arr = array();
        if(!empty($excel_array)){
            foreach($excel_array as $k => $v){
                $tmp = [];
                $tmp['codeName'] = $v[0];
                $arr[] = $tmp;
            }
            $rs = Db::name('truckcode')->insertAll($arr);
            print_r($rs);
        }*/

        /*$tx_customer = array(
          array('customerId' => '1','customerName' => '1号坑口','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '2','customerName' => '2号坑口','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '3','customerName' => '3号坑口','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '4','customerName' => '4号坑口','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '5','customerName' => '1号斜坡道','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '6','customerName' => '2号斜坡道','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '7','customerName' => '3号斜坡道','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '8','customerName' => '5号斜坡道','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '9','customerName' => '1号竖井','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '10','customerName' => '2号竖井','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '11','customerName' => '3号竖井','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '12','customerName' => '副井','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '13','customerName' => '7号竖井','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '14','customerName' => '三条沟平硐','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '15','customerName' => '8号竖井','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '16','customerName' => '一选厂细毛料','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '17','customerName' => '4号斜坡道','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '18','customerName' => '6号斜坡道','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '19','customerName' => '手捡矿石','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '20','customerName' => '1号风井','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '21','customerName' => '小冰沟','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '22','customerName' => '料场','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '23','customerName' => '二条沟破碎站','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '24','customerName' => '山尖沟平硐','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '25','customerName' => '破碎站1','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '26','customerName' => '破碎站2','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '27','customerName' => '二选厂','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '28','customerName' => '四选厂','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '29','customerName' => '青龙河','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '30','customerName' => '二斜毛坡','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '31','customerName' => '三坑拉土','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1'),
          array('customerId' => '32','customerName' => '石玖渣子站','phone' => '','address' => '','receiveHouse' => '1,2,3,4','dataFlag' => '1')
        );
        $arr = array();
        foreach($tx_customer as $k=>$v){
          $arr[] = $v['customerName'];
        }
        var_dump($arr);*/
        //return $this->fetch('test');
    }

    public function showsql(){
        $rs = Db::name('weighbill')->where(array('billDate'=>1525190400,'truckCode'=>'T03'))->field('max(fullTime) as fullTime,billId,billDate,truckCode')->find();
        print_r($rs);
    }

    public function printpage(){
        return $this->fetch('printpage');
    }


    /***
    *
    *上传车辆图片
    *
    ***/
    public function uploadbillpicture(){
        $rs = TXUploadFile();
        echo $rs;
    }


    


}

